﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core
{
    public class ServicePriorityAttribute : Attribute
    {
        public const int MaxPriority = 65535;
        public const int DefaultPriority_NONE = 0;
        public const int DefaultPriority_COFE = 100;
        public const int DefaultPriority_COFEIO = DefaultPriority_COFE + 1;
        public const int DefaultPriority_COFEMEDIA = DefaultPriority_COFEIO + 1;
        public const int DefaultPriority_COFEDB = 200;
        public const int DefaultPriority_COFEWS = 300;

        public ServicePriorityAttribute(int priority)
        {
            Priority = priority;
        }

        /// <summary>
        /// Higher Priority means first.
        /// </summary>
        public int Priority { get; private set; }

        public static int GetPriority(object obj)
        {        	             
            var a = obj.GetType().GetTypeInfo()
                .GetCustomAttribute<ServicePriorityAttribute>();
        	return a == null ? 0 : a.Priority;
        }
    }
}
